package com.nuoniu.sibanyun.controller.system;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.DictDataSaveDto;
import com.nuoniu.sibanyun.entity.dto.DictDataSearchDto;
import com.nuoniu.sibanyun.service.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-05-25
 */
@RestController
@RequestMapping("/dictData")
@Api(tags = "字典数据表")
public class SysDictDataController extends BaseController {

    @Autowired
    private ISysDictDataService sysDictDataService;

    @ApiOperation("获取字典数据列表")
    @GetMapping("/system/page")
    public HttpResult page(DictDataSearchDto dictDataSearchDto){
        return HttpResult.ok(sysDictDataService.page(dictDataSearchDto));
    }

    @ApiOperation("保存字典")
    @PostMapping("/system/saveOrUpdate")
    public HttpResult saveOrUpdate(@RequestBody DictDataSaveDto dictDataSaveDto){
        return HttpResult.ok(sysDictDataService.saveOrUpdate(dictDataSaveDto,request));
    }


//    @ApiOperation("保存排序")
//    @PostMapping("/system/saveSort")
//    public HttpResult saveSort(@RequestBody List<DictTypeSearchDto> dataList) {
//
//        return HttpResult.ok();
//    }
//

    @ApiOperation("停用")
    @PutMapping("/system/disable")
    public HttpResult disable(Long id){
        return HttpResult.ok(sysDictDataService.updateStatus(id,2,request));
    }

    @ApiOperation("启用")
    @PutMapping("/system/enable")
    public HttpResult enable(Long id){
        return HttpResult.ok(sysDictDataService.updateStatus(id,0,request));
    }

    @ApiOperation("删除")
    @DeleteMapping("/system/delete")
    public HttpResult delete(Long id){
        return HttpResult.ok(sysDictDataService.delete(id,request));
    }
}
